package com.hbnu.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class WebSocketBeanUtil implements ApplicationContextAware {

    // 静态上下文对象，用于静态访问 Spring Bean
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        WebSocketBeanUtil.applicationContext = applicationContext; // ⚠️ 正确设置
    }

    public static <T> T getBean(Class<T> clazz) {
        return applicationContext.getBean(clazz); // ✅ 访问静态变量 applicationContext
    }
}